<!DOCTYPE html>
<html lang="en">
<head>
    <!--编码格式-->
    <meta charset="UTF-8">
    <!--强制ie使用最新的edge引擎，chrome使用最新版本-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!--双核模拟器，采用webkit内核-->
    <meta name="renderer" content="webkit"/>
    <!--移动端视窗-->
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <!--页面描述-->
    <meta name="Description" content=""/>
    <!--关键字-->
    <meta name="Keywords" content=""/>
    <title>示例代码</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        html,body{
            height: 100%;
            text-align: center;
        }
        #game{
            background: url("image/poker_bg.jpg") no-repeat;
            margin: 0 auto;
            width: 1500px;
            height: 939px;
            display: none;
            position: relative;
        }
        .player_one{
            position: relative;
            left: 40px;
            top: 50px;
        }
        .lc{
            text-align: center;
            position: absolute;
            top: 500px;
            left: 0px;
        }
        .lc span{
            display: block;
            font-size: 30px;
            color: aliceblue;
        }
        .player_two{
            position: relative;
            right: -1360px;
            top: 50px;
        }
        .ldx{
            text-align: center;
            position: absolute;
            top: 500px;
            left: -5px;
        }
        .ldx span{
            display: block;
            font-size: 30px;
            color: aliceblue;
        }
        .me{
            position: relative;
            left: 500px;
            bottom: -750px;
        }
        .zzz{
            text-align: center;
            position: absolute;
            top: 0px;
            left: -190px;
        }
        .zzz span{
            display: block;
            font-size: 30px;
            color: aliceblue;
        }
        #wait{
            display: none;
        }
        .go{
            position: absolute;
            width: 80px;
            height: 40px;
            border-radius: 10px;
            background-color: darkgray;
            color: darkorchid;
            top: 670px;
            left: 800px;
            font-size: 20px;
            line-height: 40px;
        }
        .pass{
            position: absolute;
            width: 80px;
            height: 40px;
            border-radius: 10px;
            background-color: darkgray;
            color: darkorchid;
            top: 670px;
            left: 950px;
            font-size: 20px;
            line-height: 40px;
        }
        .get{
            position: absolute;
            width: 80px;
            height: 40px;
            border-radius: 10px;
            background-color: aquamarine;
            color: darkorchid;
            top: 670px;
            left: 1100px;
            font-size: 20px;
            line-height: 40px;
        }
        .move{
            top: -30px !important;
        }
        .miss{
            animation: gg 0.5s linear ;
            z-index: 100;
        }
        @keyframes gg{
            0%{
                top: -30px;
                opacity: 1;
            }
            25%{
                top: -130px;
                opacity: 1;
            }
            50%{
                top: -230px;
                opacity: 0.75;
            }
            75%{
                top: -330px;
                opacity: 0.5;
            }
            100%{
                top: -430px;
                opacity: 0.25;
            }
        }
        #table{
            position: absolute;
            width: 900px;
            height: 400px;
            border-radius: 10px;
            top: 220px;
            left: 300px;
            border: 1px solid yellowgreen;
            background: green;
        }
        #who{
            width: 400px;
            height: 80px;
            position: absolute;
            z-index: 50;
            top: 550px;
            left: 568px;
            color: white;
            text-align: center;
            font-size: 30px;
        }
        #buttom-poker{
            position: absolute;
            width: 482px;
            height: 165px;
            border-radius: 10px;
            top: 20px;
            left: 500px;
        }
        #buttom-poker>img{
            border: 1px solid greenyellow;
            margin-right: 50px;
        }
        .success{
            position: relative;
            z-index: 5000;
            display: none;
            margin: 0 auto;
            text-align: center;
        }
        .winner_img{
            margin-top: 50px;
            width: 600px;
        }
        .success_player{
            width: 600px;
            height: 100px;
            text-align: center;
            line-height: 100px;
            font-size: 40px;
            color: red;
            background-color: white;
            margin-top: -5px;
            margin-left: 450px;
        }
    </style>
</head>
<body>
<div id="wait">正在等待其他玩家</div>
<div class="bg" id="game">
    <div id="player_one" class="player_one">
        <div class="lc">
            <img src="image/lc.jpg" class="photo">
            <span>玩家1</span>
        </div>
    </div>
    <div id="player_two" class="player_two">
        <div class="ldx">
            <img src="image/ldx.png" class="photo">
            <span>玩家2</span>
        </div>
    </div>
    <div id="me" class="me">
        <div class="zzz">
            <img src="image/zzz.jpg" class="photo">
            <span>玩家3</span>
        </div>
        <div id="fuck"></div>
    </div>
    <button class="go" id="send">出牌</button>
    <button class="pass" id="pass">过</button>
    <button class="get" id="get">抢地主</button>
    <div class="success" id="success">
        <img class="winner_img" src="image/winner.png">
        <div class="success_player"><span id="winner"></span>Winner!</div>
    </div>
    <div id="who"></div>
    <div id="table"></div>
    <div id="buttom-poker">
        <img class="btmpoker" src="image/影月谷~11.jpg" alt="">
        <img class="btmpoker" src="image/影月谷~11.jpg" alt="">
        <img class="btmpoker" src="image/影月谷~11.jpg" alt="">
    </div>
</div>
<input id="client-name" type="text" placeholder="请输入名字">
<button id="go">开始游戏</button>
<script>
    var clientName = document.getElementById("client-name");
    var go = document.getElementById("go");
    var player_one = document.getElementById('player_one');
    var player_two = document.getElementById('player_two');
    var game = document.getElementById("game");
    var me = document.getElementById('me');
    var wait = document.getElementById("wait");
    var span = document.getElementsByTagName("span");
    var photo = document.getElementsByClassName("photo");
    var ws = new WebSocket("ws://localhost:8180");
    var getBtn = document.getElementById("get");
    var send = document.getElementById('send');
    var pass = document.getElementById('pass');
    var fuck = document.getElementById("fuck");
    var bottomPoker = document.getElementById("buttom-poker");
    var table = document.getElementById("table");
    var who = document.getElementById("who");
    var success = document.getElementById("success");
    var winner = document.getElementById("winner");
     var gamer = {};
    var myPoker =[];
    var main_poker = [];
    //建立连接时 触发的事件
    function sortJson(json){
        for (var i = 0; i < json.length; i++) {
            for (var j = 0; j < json.length-1; j++) {
                if (json[j].num > json[j+1].num) {
                    var temp=json[j];
                    json[j]=json[j+1];
                    json[j+1]=temp;
                }else if(json[j].num == json[j+1].num && json[j].color > json[j+1].color){
                    var temp=json[j];
                    json[j]=json[j+1];
                    json[j+1]=temp;
                }
            }
        }
        return json;
    }
//往后台发送消息
    function sendMessage(user,msg) {
        //像服务器发送消息
        ws.send(JSON.stringify({
            user:user,
            msg:msg
        }));
    }
//发送抢地主消息
    function qiangdizhu(){
        sendMessage(gamer.me,{
            func:'QDZ'
        })
    }
//发送出牌消息
    function chupai(pais){

        if(pais.length == 0){
            sendMessage(gamer.me,{
                func:"GP"
            });
        }else {
            sendMessage(gamer.me,{
                func:"CP",
                cont:pais
            });
        }


    }
//发送胜利消息
    function victory(){
        sendMessage(gamer.me,{
            func:"WIN"
        });
    }
// 画玩家扑克
    function create_player(player){
        for(var i= 0; i < 17; i++){
            var img = document.createElement('img');
            img.src = 'image/影月谷~11.jpg';
            img.style.position = 'absolute';
            img.style.top = 20*i + 'px';
            img.style.left = 0;
            player.appendChild(img);
        }
    }
// 画本人扑克
    function create_me(player,arr){
        if(gamer.switch == "open"){
             player.innerHTML = "";
        }
        for(var i= 0; i < arr.length; i++){
            var img = document.createElement('img');
            img.src = "image/poker_" + arr[i].num + "_" + arr[i].color + ".jpg";
            img.style.position = 'absolute';
            img.style.top = 0;
            img.style.left = 20 * i + 'px';
            img.style.transition = "all 0.2s ease-in-out";
            img.setAttribute('index','0');
            player.appendChild(img);
        }
        gamer.switch = "open";
    }

    function create_main_poker(player,arr){
        if(gamer.switch == "open"){
            player.innerHTML = "";
        }
        for(var i= 0; i < arr.length; i++){
            var img = document.createElement('img');
            img.src = arr[i].src;
            player.appendChild(img);
        }
        gamer.switch = "open";
    }
    function aaa(event) {
        event.preventDefault();
        event.stopPropagation();
        var index = event.target.getAttribute('index');
        if (index == 0) {
            event.target.setAttribute('class', 'move');
            event.target.setAttribute('index', "1");
        }else{
            if (event.target.getAttribute('class') == 'move') {
                event.target.removeAttribute('class');
                event.target.setAttribute('index', "0");
            }
        }
    }
    function bbb(event) {
        event.preventDefault();
        event.stopPropagation();
        var index = event.target.getAttribute('index');
        if (index == 0) {
            event.target.setAttribute('class', 'move');
            event.target.setAttribute('index', "1");
        }
    }

    function suc(player){
        success.style.display = 'block';
        winner.innerHTML = player;
    };
    ws.onopen = function (e) {
        console.log('Connection to server opened');
    };

    //连接关闭时 触发的事件
    ws.onclose = function(e){
        console.log("close");
    };

    //收到服务器消息的时候 触发的事件
    ws.onmessage = function(e){
        var data =  JSON.parse(e.data);
        if (data.func == "sendPoker"){
            myPoker = sortJson(data.poker);
            console.log(myPoker);
            create_player(player_one);
            create_player(player_two);
            create_me(fuck,myPoker);
            wait.style.display = "none";
            game.style.display = "block";
            gamer.me = data.user;
            for (var i = 0;i < data.all.length;i++){
                if (data.all[i] == data.user){
                    switch (i){
                        case 0:
                           gamer.next = data.all[1];
                           gamer.last = data.all[2];
                            photo[2].src = "image/lc.jpg";
                            photo[0].src = "image/zzz.jpg";
                            photo[1].src = "image/ldx.png";

                        break;
                        case 1:
                            gamer.next = data.all[2];
                            gamer.last = data.all[0];
                            photo[2].src = "image/ldx.png";
                            photo[0].src = "image/lc.jpg";
                            photo[1].src = "image/zzz.jpg";
                        break;
                        case 2:
                            gamer.next = data.all[0];
                            gamer.last = data.all[1];
                            photo[2].src = "image/zzz.jpg";
                            photo[0].src = "image/ldx.png";
                            photo[1].src = "image/lc.jpg";
                            break;

                    }
                }
            }
            span[2].innerHTML = data.user;
            span[1].innerHTML = gamer.next;
            span[0].innerHTML = gamer.last;
        }
        if (data.func == "qiangdizhu"){
            myPoker = sortJson(data.poker);
            gamer.fuck = "open";
            send.style.backgroundColor = "aquamarine";
            pass.style.backgroundColor = "aquamarine";
            who.innerHTML = "轮到"+ data.user + "地主出牌";
            create_me(fuck,myPoker);
        }
        if (data.func == "bottom"){
            console.log(data.bottom);
            var onlyBottom = bottomPoker.children;
            for (var i = 0;i < 3 ;i++){
                onlyBottom[i].src = data.bottom[i].src;
            }
            getBtn.style.display = "none"

        }
        if(data.func == "chupai"){
            gamer.nowPlayer = data.user;
             who.innerHTML = data.user+"已经出过牌,请下家出牌";
            if (gamer.nowPlayer == gamer.last){
                gamer.fuck = "open";
                send.style.backgroundColor = "aquamarine";
                pass.style.backgroundColor = "aquamarine";

            }
            if(data.poker.length != 0){
                console.log(data.poker);
                gamer.poker = data.poker;
                create_main_poker(table,data.poker);
            }

        }

        if (data.func == "guopai"){
            gamer.nowPlayer = data.user[0];
            who.innerHTML = data.user[1]+"选择了过牌,请下家出牌";
            if (data.user[1] == gamer.last){
                gamer.fuck = "open";
                send.style.backgroundColor = "aquamarine";
                pass.style.backgroundColor = "aquamarine";

            }
            if(data.poker.length != 0){
                gamer.poker = data.poker;
                create_main_poker(table,data.poker);
            }

        }

        if (data.func == "victory"){
            //alert("游戏结束!  "+ data.user+"赢得了比赛");
            suc(data.user);
        }
    };

    me.addEventListener('mousedown', function(event) {

        aaa(event);
        me.addEventListener('mousemove', bbb)
    });
    me.addEventListener('mouseup', function(){
        me.removeEventListener('mousemove', bbb);
    });
    // 过牌动画
    pass.onclick = function(){
        var imgArr = fuck.children;
        for (var i= 0; i < imgArr.length; i++){
            if(imgArr[i].getAttribute('index') == 1){
                imgArr[i].removeAttribute('class');
                imgArr[i].setAttribute('index', "0");
            }
        }

        chupai([]);
        if(gamer.fuck == "open"){
            alert("你选择了过牌了");
        }
        send.style.backgroundColor = "darkgray";
        pass.style.backgroundColor = "darkgray";
        gamer.fuck = "close"
    };
    // 出牌动画
    // 出牌删除手中所出的牌
    send.onclick = function(){
        if (gamer.fuck == "open") {
            var new_main_poker = [];
            var imgArr = fuck.children;
            for (var i = 0; i < imgArr.length; i++) {
                if (imgArr[i].getAttribute("index") == 1) {

                    imgArr[i].className += " miss";
                    for (var j = 0; j < myPoker.length; j++) {
                        if (myPoker[j].src == imgArr[i].getAttribute('src')) {
                            new_main_poker.push(myPoker[j]);
                            myPoker.splice(j, 1);
                            j--;
                            if (j <= 0) {
                                j = 0;
                            }
                        }
                    }
                    main_poker = new_main_poker;
                }
            }
            rational(main_poker);

            if (gamer.poker == undefined || gamer.my == gamer.nowPlayer){
                gamer.contrast = "ok" ;
                gamer.new = "ok";
            }else {
                contrast(gamer.poker,main_poker);
            }

            if (gamer.rational == "ok"&& gamer.contrast == "ok" && gamer.new == "ok"){

                    setTimeout(function () {
                        create_me(fuck, myPoker);
                        chupai(main_poker);
                        gamer.fuck = "close";
                        send.style.backgroundColor = "darkgray";
                        pass.style.backgroundColor = "darkgray";
                        gamer.rational = "no";
                        gamer.contrast = "no";
                        gamer.new = "no";
                        if (imgArr.length == 0) {
                            victory();
                        }
                    }, 500)

        }else {
                myPoker = myPoker.concat(main_poker);
                sortJson(myPoker);
                create_me(fuck, myPoker);
                alert("你出的牌不符合规则");

            }
        }
    };

    go.onclick = function(){
        gamer.my = clientName.value;
        sendMessage(clientName.value,"null");
        go.remove();
        clientName.remove();
        wait.style.display = "block"
    };
    getBtn.onclick = function(){
        qiangdizhu();
    };


    function rational(pai){
//单张
        if(pai.length == 1  ){
            gamer.rational = "ok";
        }
//对子
        if(pai.length == 2 && pai[0].num==pai[1].num){
            gamer.rational = "ok";
        }

//三张
        if(pai.length == 3 && pai[0].num==pai[1].num &&pai[0].num ==pai[2].num ){
            gamer.rational = "ok";
        }

//三带一(后)
        if(pai.length == 4 && pai[0].num==pai[1].num &&pai[0].num ==pai[2].num && pai[0].num!=pai[3].num){
            gamer.rational = "ok";
        }


//三带一(前)
        if(pai.length == 4 && pai[1].num==pai[2].num &&pai[1].num ==pai[3].num && pai[0].num!=pai[1].num){
            gamer.rational = "ok";
        }


//三带对(后)
        if(pai.length == 5 && pai[0].num==pai[1].num &&pai[0].num ==pai[2].num && pai[0].num!=pai[3].num && pai[3].num ==pai[4].num ){
            gamer.rational = "ok";
        }

//三带对(前)
        if(pai.length == 5 && pai[2].num==pai[3].num &&pai[2].num ==pai[4].num && pai[2].num!=pai[1].num && pai[1].num ==pai[0].num ){
            gamer.rational = "ok";
        }

//飞机(2)带单(后)
        if(pai.length == 8 && pai[0].num==pai[1].num && pai[0].num ==pai[2].num && pai[3].num == pai[4].num && pai[3].num == pai[5].num  && pai[0].num != pai[6].num && pai[0].num != pai[7].num && pai[3].num-pai[0].num == 1 && pai[6].num != pai[7].num && pai[3].num != pai[6].num && pai[3].num != pai[7].num){
            gamer.rational = "ok";
        }

//飞机(2)带单(前)
        if(pai.length == 8 && pai[2].num==pai[3].num && pai[2].num ==pai[4].num && pai[5].num == pai[6].num && pai[5].num == pai[7].num  && pai[0].num != pai[2].num && pai[0].num != pai[7].num && pai[5].num-pai[4].num == 1 && pai[0].num != pai[1].num && pai[1].num != pai[2].num && pai[1].num != pai[7].num){
            gamer.rational = "ok";
        }

//飞机(2)带单(前)(后)
        if(pai.length == 8 && pai[1].num==pai[2].num && pai[1].num ==pai[3].num && pai[4].num == pai[5].num && pai[4].num == pai[6].num  && pai[0].num != pai[1].num && pai[0].num != pai[6].num && pai[4].num-pai[3].num == 1 && pai[7].num != pai[1].num && pai[7].num != pai[4].num && pai[0].num != pai[7].num){
            gamer.rational = "ok";
        }


//飞机(2)带对(后)
        if(pai.length == 10 && pai[0].num==pai[1].num && pai[0].num ==pai[2].num && pai[3].num == pai[4].num && pai[3].num == pai[5].num  && pai[0].num != pai[6].num && pai[0].num != pai[8].num && pai[3].num-pai[0].num == 1 && pai[3].num != pai[6].num && pai[3].num != pai[8].num && pai[6].num != pai[8].num && pai[6].num == pai[7].num&& pai[8].num == pai[9].num){
            gamer.rational = "ok";
        }

//飞机(2)带对(前)
        if(pai.length == 10 && pai[4].num==pai[5].num && pai[4].num ==pai[6].num && pai[7].num == pai[8].num && pai[7].num == pai[9].num  && pai[0].num != pai[6].num && pai[0].num != pai[8].num && pai[7].num-pai[6].num == 1 && pai[3].num != pai[6].num && pai[3].num != pai[8].num && pai[0].num != pai[2].num && pai[0].num == pai[1].num && pai[2].num == pai[3].num){
            gamer.rational = "ok";
        }

//飞机(2)带对(前)(后)
        if(pai.length == 10 && pai[2].num==pai[3].num && pai[2].num ==pai[4].num && pai[5].num == pai[6].num && pai[5].num == pai[7].num  && pai[0].num != pai[2].num && pai[0].num != pai[5].num && pai[5].num-pai[4].num == 1 && pai[1].num != pai[4].num && pai[1].num != pai[5].num && pai[0].num != pai[8].num && pai[0].num == pai[1].num && pai[8].num == pai[9].num){
            gamer.rational = "ok";
        }


//飞机(2)不带
        if(pai.length == 6 && pai[0].num==pai[1].num && pai[0].num ==pai[2].num && pai[3].num == pai[4].num && pai[3].num == pai[5].num   && pai[3].num-pai[0].num == 1 ){
            gamer.rational = "ok";
        }

//顺子
        var  aa = 0;
        for(var i = 0; i<pai.length-1;i++){
            if(pai[i].num - pai[i+1].num == -1){
                aa++;
                if (aa == pai.length-1 && pai.length > 4){
                    gamer.rational = "ok";
                }
            }
        }



//连对
        if(pai.length >= 6 && pai.length%2 == 0) {
            var cc =0;
            for(var i = 0; i<pai.length-2;i+=2){

                if(pai[i].num == pai[i+1].num && pai[i].num - pai[i+2].num == -1  ){
                    cc++;

                    if (cc == (pai.length-2)/2 && pai[pai.length-1].num == pai[pai.length-2].num  ){
                        gamer.rational = "ok";
                    }
                }
            }
        }

//炸弹
        if (pai.length ==4 && pai[0].num == pai[1].num && pai[0].num == pai[2].num && pai[0].num == pai[3].num  ){
            gamer.rational = "ok";
        }

    }
    /**
     * Created by dllo on 17/6/8.
     */
    function contrast (pai,xpai){

//单张
        if(pai.length == 1){
            gamer.new = "ok";
        }

// 单张下家
        if(xpai.length == 1 && xpai.length == pai.length && xpai[0].num>pai[0].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }

//对子
        if(pai.length == 2 && pai[0].num==pai[1].num){
            gamer.new = "ok";
        }

//对子 下家
        if(xpai.length == 2 && xpai.length == pai.length && xpai[0].num==xpai[1].num && xpai[0].num >pai[0].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }

//三张
        if(pai.length == 3 && pai[0].num==pai[1].num &&pai[0].num ==pai[2].num ){
            gamer.new = "ok";
        }
//三张下家
        if(xpai.length == 3 && xpai.length == pai.length && xpai[0].num==xpai[1].num  && xpai[0].num==xpai[2].num && xpai[0].num >pai[0].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }
//三带一(后)
        if(pai.length == 4 && pai[0].num==pai[1].num &&pai[0].num ==pai[2].num && pai[0].num!=pai[3].num){
            gamer.new = "ok";
        }
//三带一下家(后)
        if(xpai.length == 4 && xpai.length == pai.length && xpai[0].num == xpai[1].num && xpai[0].num == xpai[2].num && xpai[0].num != xpai[3].num && xpai[0].num >pai[0].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }

//三带一(前)
        if(pai.length == 4 && pai[1].num==pai[2].num &&pai[1].num ==pai[3].num && pai[0].num!=pai[1].num){
            gamer.new = "ok";
        }
//三带一下家(前)
        if(xpai.length == 4 && xpai.length == pai.length && xpai[1].num == xpai[2].num && xpai[1].num == xpai[3].num && xpai[0].num != xpai[1].num && xpai[1].num >pai[1].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }

//三带对(后)
        if(pai.length == 5 && pai[0].num==pai[1].num &&pai[0].num ==pai[2].num && pai[0].num!=pai[3].num && pai[3].num ==pai[4].num ){
            gamer.new = "ok";
        }
//三带对下家(后)
        if(xpai.length == 5 && xpai.length == pai.length && xpai[0].num == xpai[1].num && xpai[0].num == xpai[2].num && xpai[0].num != xpai[3].num && xpai[0].num >pai[0].num && xpai[3].num == xpai[4].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num ){
            gamer.contrast = "ok";
        }
//三带对(前)
        if(pai.length == 5 && pai[2].num==pai[3].num &&pai[2].num ==pai[4].num && pai[2].num!=pai[1].num && pai[1].num ==pai[0].num ){
            gamer.new = "ok";
        }
//三带对下家(前)
        if(xpai.length == 5 && xpai.length == pai.length && xpai[2].num == xpai[3].num && xpai[2].num == xpai[4].num && xpai[0].num != xpai[2].num && xpai[2].num >pai[2].num && xpai[0].num == xpai[1].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }
//飞机(2)带单(后)
        if(pai.length == 8 && pai[0].num==pai[1].num && pai[0].num ==pai[2].num && pai[3].num == pai[4].num && pai[3].num == pai[5].num  && pai[0].num != pai[6].num && pai[0].num != pai[7].num && pai[3].num-pai[0].num == 1 && pai[6].num != pai[7].num && pai[3].num != pai[6].num && pai[3].num != pai[7].num){
            gamer.new = "ok";
        }
//下家 飞机(2)带单(后)
        if(xpai.length == 8 && xpai.length == pai.length && xpai[0].num == xpai[1].num && xpai[0].num == xpai[2].num && xpai[3].num == xpai[4].num && xpai[3].num == xpai[5].num  && xpai[0].num != xpai[6].num && xpai[0].num != xpai[7].num && xpai[3].num - xpai[0].num == 1 && xpai[0].num >pai[0].num && xpai[6].num != xpai[7].num && xpai[3].num != xpai[6].num && xpai[3].num != xpai[7].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }
//飞机(2)带单(前)
        if(pai.length == 8 && pai[2].num==pai[3].num && pai[2].num ==pai[4].num && pai[5].num == pai[6].num && pai[5].num == pai[7].num  && pai[0].num != pai[2].num && pai[0].num != pai[7].num && pai[5].num-pai[4].num == 1 && pai[0].num != pai[1].num && pai[1].num != pai[2].num && pai[1].num != pai[7].num){
            gamer.new = "ok";
        }
//下家 飞机(2)带单(前)
        if(xpai.length == 8 && xpai.length == pai.length && xpai[2].num == xpai[3].num && xpai[4].num == xpai[2].num && xpai[5].num == xpai[6].num && xpai[5].num == xpai[7].num  && xpai[0].num != xpai[2].num && xpai[0].num != xpai[7].num && xpai[5].num - xpai[4].num == 1 && xpai[2].num >pai[2].num && xpai[1].num != xpai[0].num && xpai[1].num != xpai[6].num && xpai[1].num != xpai[2].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }
//飞机(2)带单(前)(后)
        if(pai.length == 8 && pai[1].num==pai[2].num && pai[1].num ==pai[3].num && pai[4].num == pai[5].num && pai[4].num == pai[6].num  && pai[0].num != pai[1].num && pai[0].num != pai[6].num && pai[4].num-pai[3].num == 1 && pai[7].num != pai[1].num && pai[7].num != pai[4].num && pai[0].num != pai[7].num){
            gamer.new = "ok";
        }
//下家 飞机(2)带单(前)(后)
        if(xpai.length == 8 && xpai.length == pai.length && xpai[1].num==xpai[2].num && xpai[1].num ==xpai[3].num && xpai[4].num == xpai[5].num && xpai[4].num == xpai[6].num  && xpai[0].num != xpai[1].num && xpai[0].num != xpai[6].num && xpai[4].num- xpai[3].num == 1 && xpai[7].num != xpai[1].num && xpai[7].num != xpai[4].num && xpai[0].num != xpai[7].num  && xpai[1].num >pai[1].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }

//飞机(2)带对(后)
        if(pai.length == 10 && pai[0].num==pai[1].num && pai[0].num ==pai[2].num && pai[3].num == pai[4].num && pai[3].num == pai[5].num  && pai[0].num != pai[6].num && pai[0].num != pai[8].num && pai[3].num-pai[0].num == 1 && pai[3].num != pai[6].num && pai[3].num != pai[8].num && pai[6].num != pai[8].num && pai[6].num == pai[7].num&& pai[8].num == pai[9].num){
            gamer.new = "ok";
        }
//下家 飞机(2)带对(后)
        if(xpai.length == 10 && xpai.length == pai.length && xpai[0].num==xpai[1].num && xpai[0].num ==xpai[2].num && xpai[3].num == xpai[4].num && xpai[3].num == xpai[5].num  && xpai[0].num != xpai[6].num && xpai[0].num != xpai[8].num && xpai[3].num-xpai[0].num == 1 && xpai[3].num != xpai[6].num && xpai[3].num != xpai[8].num && xpai[6].num != xpai[8].num && xpai[6].num == xpai[7].num && xpai[8].num == xpai[9].num && xpai[0].num > pai[0].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }
//飞机(2)带对(前)
        if(pai.length == 10 && pai[4].num==pai[5].num && pai[4].num ==pai[6].num && pai[7].num == pai[8].num && pai[7].num == pai[9].num  && pai[0].num != pai[6].num && pai[0].num != pai[8].num && pai[7].num-pai[6].num == 1 && pai[3].num != pai[6].num && pai[3].num != pai[8].num && pai[0].num != pai[2].num && pai[0].num == pai[1].num && pai[2].num == pai[3].num){
            gamer.new = "ok";
        }
//下家 飞机(2)带对(前)
        if(xpai.length == 10 && xpai.length == pai.length && xpai[4].num==xpai[5].num && xpai[4].num ==xpai[6].num && xpai[7].num == xpai[8].num && xpai[7].num == xpai[9].num  && xpai[0].num != xpai[6].num && xpai[0].num != xpai[8].num && xpai[7].num-xpai[6].num == 1 && xpai[3].num != xpai[6].num && xpai[3].num != xpai[8].num && xpai[3].num != xpai[6].num && xpai[0].num == xpai[1].num && xpai[2].num == xpai[3].num && xpai[4].num > pai[4].num|| xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }
//飞机(2)带对(前)(后)
        if(pai.length == 10 && pai[2].num==pai[3].num && pai[2].num ==pai[4].num && pai[5].num == pai[6].num && pai[5].num == pai[7].num  && pai[0].num != pai[2].num && pai[0].num != pai[5].num && pai[5].num-pai[4].num == 1 && pai[1].num != pai[4].num && pai[1].num != pai[5].num && pai[0].num != pai[8].num && pai[0].num == pai[1].num && pai[8].num == pai[9].num){
            gamer.new = "ok";
        }
//下家 飞机(2)带对(前)(后)
        if(xpai.length == 10 && xpai.length == pai.length && xpai[2].num==xpai[3].num && xpai[2].num ==xpai[4].num && xpai[5].num == xpai[6].num && xpai[5].num == xpai[7].num  && xpai[0].num != xpai[2].num && xpai[0].num != xpai[5].num && xpai[5].num-xpai[4].num == 1 && xpai[1].num != xpai[4].num && xpai[1].num != xpai[5].num && xpai[0].num != xpai[8].num && xpai[0].num == xpai[1].num && xpai[8].num == xpai[9].num && xpai[4].num > pai[4].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
            gamer.contrast = "ok";
        }

//飞机(2)不带
        if(pai.length == 6 && pai[0].num==pai[1].num && pai[0].num ==pai[2].num && pai[3].num == pai[4].num && pai[3].num == pai[5].num   && pai[3].num-pai[0].num == 1 ){
            gamer.new = "ok";
        }
//下家 飞机(2)不带
        if(xpai.length == 6 && xpai.length == pai.length && xpai[0].num== xpai[1].num && xpai[0].num == xpai[2].num && xpai[3].num == xpai[4].num && xpai[3].num == xpai[5].num && xpai[3].num - xpai[0].num == 1 && xpai[0].num > pai[0].num || xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num ){
            gamer.contrast = "ok";
        }
//顺子
        var ff = 1;
        var  aa = 0;
        for(var i = 0; i<pai.length-1;i++){
            if(pai[i].num - pai[i+1].num == -1){
                aa++;
                if (aa == pai.length-1 && pai.length > 4){
                    gamer.new = "ok";
                    ff = 2;
                }
            }
        }

//下家  顺子
        var  bb = 0;
        for(var i = 0; i<xpai.length-1;i++){
            if(xpai[i].num - xpai[i+1].num == -1){
                bb++;
                if (bb == pai.length-1 && xpai.length == pai.length && xpai[0].num > pai[0].num ){
                    gamer.contrast = "ok";
                }
            }
        }
//上家顺子  下家炸弹
        if (ff == 2){
            if( xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
                gamer.contrast = "ok";
                ff=1;
            }
        }

//连对
        var qq = 1;
        if(pai.length >= 6 && pai.length%2 == 0) {
            var cc =0;
            for(var i = 0; i<pai.length-2;i+=2){

                if(pai[i].num == pai[i+1].num && pai[i].num - pai[i+2].num == -1  ){
                    cc++;

                    if (cc == (pai.length-2)/2 && pai[pai.length-1].num == pai[pai.length-2].num  ){
                        gamer.new = "ok";
                        qq = 2;
                    }
                }
            }
        }

//连对 下家
        if(xpai.length >= 6 && xpai.length%2 == 0 && xpai.length == pai.length ) {
            var dd =0;
            for(var i = 0; i<xpai.length-2;i+=2){
                if(xpai[i].num == xpai[i+1].num && xpai[i].num - xpai[i+2].num == -1  ){
                    dd++;
                    if (dd == (xpai.length-2)/2 && xpai[xpai.length-1].num == xpai[xpai.length-2].num && xpai[0].num > pai[0].num ){
                        gamer.contrast = "ok";
                    }
                }
            }
        }

//上家连对  下家炸弹
        if (qq == 2){
            if( xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num){
                gamer.contrast = "ok";
                qq=1;

            }
        }


//炸弹
        if (pai.length ==4 &&  pai[0].num == pai[1].num &&  pai[0].num == pai[2].num&&  pai[0].num == pai[3].num  ){
            gamer.new = "ok";
        }
//下家炸弹
        if (xpai[0].num >= pai[0].num && xpai.length ==4 &&  xpai[0].num == xpai[1].num &&  xpai[0].num == xpai[2].num&&  xpai[0].num == xpai[3].num  ){
            gamer.contrast = "ok";
        }
    }
</script>
</body>
</html>